﻿<Window x:Class="Brjnk.GpxExplorer.UI.ManageMapSourcesWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:Brjnk.GpxExplorer.Localization"
        Title="{l:Loc titleManageMaps}"
        Width="400"
        Height="400"
        MinWidth="400"
        MinHeight="400"
        FocusManager.FocusedElement="{Binding ElementName=okButton}"
        WindowStartupLocation="CenterOwner">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <StackPanel Orientation="Vertical">
            <TextBlock Text="{l:Loc manageMapSourcesInfo}" TextWrapping="Wrap" />
            <TextBlock Name="infoLink" Style="{StaticResource LinkStyle}">http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames</TextBlock>
            <TextBlock Name="sourcesLink" Style="{StaticResource LinkStyle}">http://wiki.openstreetmap.org/wiki/Tiles</TextBlock>
        </StackPanel>

        <ListView Name="sources"
                  Grid.Row="1"
                  Grid.RowSpan="3"
                  ItemsSource="{Binding CustomSources}"
                  SelectionMode="Single">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding SourceNameSerializable}" />
                        <Ellipse Grid.Column="1"
                                 Width="{Binding RelativeSource={RelativeSource Mode=Self},
                                                 Path=ActualHeight}"
                                 Fill="Pink"
                                 Stroke="Red"
                                 StrokeThickness="2"
                                 ToolTip="{l:Loc mapInvalidMapSource}">
                            <Ellipse.Style>
                                <Style TargetType="Ellipse">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsInvalid}" Value="False">
                                            <Setter Property="Visibility" Value="Collapsed" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Ellipse.Style>
                        </Ellipse>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <Button Name="okButton"
                Grid.Row="0"
                Grid.Column="1"
                VerticalAlignment="Top"
                Click="Button_Click"
                Content="{l:Loc Ok}"
                IsDefault="True" />
        <Button Grid.Row="2"
                Grid.Column="1"
                VerticalAlignment="Top"
                Command="{Binding AddCustomSourceCommand}"
                Content="{l:Loc manageMapSourcesAdd}" />
        <Button Grid.Row="3"
                Grid.Column="1"
                VerticalAlignment="Top"
                Command="{Binding RemoveCustomSourceCommand}"
                CommandParameter="{Binding ElementName=sources,
                                           Path=SelectedItem}"
                Content="{l:Loc manageMapSourcesRemove}" />

        <Grid Grid.Row="4" Grid.ColumnSpan="2">
            <Grid.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=sources, Path=SelectedItems.Count}" Value="0">
                            <Setter Property="Grid.IsEnabled" Value="False" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <TextBlock Grid.Row="0" Text="{l:Loc manageMapSourcesName}" />
            <TextBlock Grid.Row="1" Text="{l:Loc manageMapSourcesUrl}" />
            <TextBlock Grid.Row="2" Text="{l:Loc manageMapSourcesMaxZoom}" />
            <TextBlock Grid.Row="3" Text="{l:Loc manageMapSourcesUniqueId}" />

            <TextBox Grid.Row="0"
                     Grid.Column="1"
                     Text="{Binding ElementName=sources,
                                    Path=SelectedItem.SourceNameSerializable}" />
            <TextBox Grid.Row="1"
                     Grid.Column="1"
                     Text="{Binding ElementName=sources,
                                    Path=SelectedItem.UrlPattern}" />
            <TextBox Grid.Row="2"
                     Grid.Column="1"
                     Text="{Binding ElementName=sources,
                                    Path=SelectedItem.MaxZoom}" />
            <TextBlock Grid.Row="3"
                       Grid.Column="1"
                       Text="{Binding ElementName=sources,
                                      Path=SelectedItem.UniqueNameSerializable}" />
        </Grid>
    </Grid>
</Window>